package core;



import java.util.ArrayList;

// This stores a set of strokes.
// Even if there are multiple users interacting with the window at the same time,
// they all interect with a single instance of this class.
public class Drawing {

	public ArrayList< Stroke > strokes = new ArrayList< Stroke >();

	private AlignedRectangle2D boundingRectangle = new AlignedRectangle2D();
	private boolean isBoundingRectangleDirty = false;

	public void addStroke( Stroke s ) {
		strokes.add( s );
		isBoundingRectangleDirty = true;
	}
	
	public void removeStroke(Stroke s) {
		for (int i = 0; i< this.strokes.size(); ++i) {
			if (strokes.get(i).equals(s)) {
				this.strokes.remove(i);
				break;
			}
		}
		isBoundingRectangleDirty = true;
	}

	public AlignedRectangle2D getBoundingRectangle() {
		if ( isBoundingRectangleDirty ) {
			boundingRectangle.clear();
			for ( Stroke s : strokes ) {
				boundingRectangle.bound( s.getBoundingRectangle() );
			}
			isBoundingRectangleDirty = false;
		}
		return boundingRectangle;
	}
	public void markBoundingRectangleDirty() {
		isBoundingRectangleDirty = true;
	}

	public void draw( GraphicsWrapper gw ) {
		gw.setLineWidth( 5 );
		for ( Stroke s : strokes ) {
			s.draw( gw );
		}
		gw.setLineWidth( 1 );
	}

}